<form method="POST">
    <table>
        <thead>
            <tr>
                <th>Controller</th>
                <?php foreach ($roles as $role) { ?>
                <th><?php echo $role->name; ?></th>
                <?php } ?>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($permissions as $permission) { ?>
            <tr>
                <td><?php echo $permission['controller']; ?></td>
                <?php foreach ($roles as $role) { ?>
                <?php if (in_array($role->id, $permission['roles'])) { ?>
                <td><input type="checkbox" checked name="permission[<?php echo $permission['controller']; ?>][]" value="<?php echo $role->id; ?>"/></td>
                <?php }else{ ?>
                <td><input type="checkbox" name="permission[<?php echo $permission['controller']; ?>][]" value="<?php echo $role->id; ?>"/></td>
                <?php } ?>
                <?php } ?>
            </tr>
            <?php } ?>
        </tbody>
    </table>
    <button>Save</button>
</form>